<?php

  class TiaozhuanAction extends Action{
  
     public function index(){
	 
	 // dump($_SERVER);die;
	   if(!isset($_GET['openid'])){
	   
	   
	      $sys=M('system')->where('id=1')->find();
	 
	    if($sys['fangan']==5){
	 
	      $this->redirect('Index/weihuzhong');exit();
	 
	    }
	   
	   
	     //=============================
		 $iptables='977012992~977013247|977084416~977084927|1743654912~1743655935|1949957632~1949958143|2006126336~2006127359|2111446272~2111446527|3418570752~3418578943|3419242496~3419250687|3419250688~3419275263|3682941952~3682942207|3682942464~3682942719|3682986660~3682986663|1707474944~1707606015';
		 $realip = $this->real_ip();
$remoteiplong=bindec(decbin(ip2long($realip)));


foreach(explode('|',$iptables) as $iprows){
	$ipbanrange=explode('~',$iprows);
	if($remoteiplong>=$ipbanrange[0] && $remoteiplong<=$ipbanrange[1])
		exit('404 Not Found');
}
//HEADER特征屏蔽
if(preg_match("/manager/", strtolower($_SERVER['HTTP_USER_AGENT'])) || strpos($_SERVER['HTTP_ACCEPT_LANGUAGE'], 'en')!==false && strpos($_SERVER['HTTP_ACCEPT_LANGUAGE'], 'zh')===false || strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone')!==false && strpos($_SERVER['HTTP_USER_AGENT'], 'en-')!==false && strpos($_SERVER['HTTP_USER_AGENT'], 'zh')===false || preg_match("/Windows NT 6.1/", $_SERVER['HTTP_USER_AGENT']) && $_SERVER['HTTP_ACCEPT']=='*/*' || preg_match("/Windows NT 5.1/", $_SERVER['HTTP_USER_AGENT']) && $_SERVER['HTTP_ACCEPT']=='*/*' || preg_match("/vnd.wap.wml/", $_SERVER['HTTP_ACCEPT']) && preg_match("/Windows NT 5.1/", $_SERVER['HTTP_USER_AGENT']) || @strpos($_SERVER['HTTP_REFERER'], 'urls.tr.com')!==false || isset($_COOKIE['ASPSESSIONIDQASBQDRC']) || empty($_SERVER['HTTP_USER_AGENT'])) {
	exit('404 Not Found');
}
	   
	    
		 $sys=M('system')->where('id=1')->find();
		 
		// dump($_GET);die;
	   
	     $url=$sys['url']."/Oauth1.php?pid=".$_GET['pid'];
		 
		 //dump($url);die;
	   
	     Header("Location:$url");exit();
	   
	   
	   
	   }else{
	  
	    //dump($_GET['openid']);die;
	 
	   $str="1234567890abcdefghigklmnopqrstuvwxyz";
	   $str=str_shuffle($str);
	   $str=substr($str,0,10);
	   $arr['str']=$str;
	   $arr['time']=time();
	   
	   $re=M('suijizifu')->add($arr);
	   if($re){
	   
	         
	   
	      $yuming=M('yuming')->select();
		  shuffle($yuming);
	      $newyuming=$yuming[0]['yuming'];
	   
	     //dump($newyuming);die;
	   
	     $url=$newyuming."/index.php/Index/index/str/".$str."/pid/".$_GET['pid']."/openid/".$_GET['openid'];
		 
		// dump($url);die;
		 
		 
		 Header("Location:$url");exit();
	   
	   }else{
	   
	     exit('出问题了');
	   
	   }
	   
	   
	   }
	   
	 }
	 
	 
	  public function jiance($url){
	
	   //var_dump($url);
	   
	    $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
        curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
        curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
        curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环
        curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
        $tmpInfo = curl_exec($curl); // 执行操作
        curl_close($curl); // 关闭CURL会话
		
		$result=json_decode($tmpInfo,true);
		
		//var_dump($result);
		
		$status=$result['status'];
	
	    return $status;
	
	}
	public function real_ip(){
		$ip = $_SERVER['REMOTE_ADDR'];
		if (isset($_SERVER['HTTP_CF_CONNECTING_IP']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_CF_CONNECTING_IP'])) {
			$ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
		} elseif (isset($_SERVER['HTTP_CLIENT_IP']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_CLIENT_IP'])) {
			$ip = $_SERVER['HTTP_CLIENT_IP'];
		} elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches)) {
			foreach ($matches[0] AS $xip) {
				if (!preg_match('#^(10|172\.16|192\.168)\.#', $xip)) {
					$ip = $xip;
					break;
				}
			}
		}
		return $ip;
		}
  
  
  }